#ifndef __BSP_IIC_H_
#define __BSP_IIC_H_

#include "debug.h"

typedef struct {
    GPIO_TypeDef*               port;
    uint16_t                    SDA_Pin;
    uint16_t                    SCK_Pin;
    GPIOSpeed_TypeDef           GPIO_Speed;
    GPIOMode_TypeDef            GPIO_Mode;
    uint32_t                    RCC_APB1Periph;
    uint32_t                    RCC_APB2Periph;

    I2C_TypeDef*        I2Cx;
    uint32_t            I2C_ClockSpeed;
    uint16_t            I2C_Mode;
    uint16_t            I2C_DutyCycle;
    uint16_t            I2C_OwnAddress1;
    uint16_t            I2C_Ack;
    uint16_t            I2C_AcknowledgedAddress;

    void (*RCC_APB1PeriphClockCmd)(uint32_t RCC_APB1Periph, FunctionalState NewState);
    void (*RCC_APB2PeriphClockCmd)(uint32_t RCC_APB2Periph, FunctionalState NewState);

}BSP_IIC_Typedef_t;

class BSP_IIC {
private:
    BSP_IIC_Typedef_t*      iic;
    void init(BSP_IIC_Typedef_t* iic);
public:
    BSP_IIC(BSP_IIC_Typedef_t* iic);
    ~BSP_IIC();

    void WaitEvent(uint32_t I2C_EVENT);
    uint8_t ReadReg(uint8_t ADDRESS, uint8_t RegAddress);
    void WriteReg(uint8_t ADDRESS, uint8_t RegAddress, uint8_t Data);

};

#endif
